package com.yinhe.group.lyq.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yinhe.common.core.domain.entity.SysUser;
import com.yinhe.common.core.domain.model.LoginUser;
import com.yinhe.group.lyq.domain.YhBorrow;
import com.yinhe.group.lyq.service.IYhBorrowService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.enums.BusinessType;

import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author yinhe
 * @date 2023-02-12
 */
@RestController
@RequestMapping("/system/borrow")
public class YhBorrowController extends BaseController
{
    @Autowired
    private IYhBorrowService yhBorrowService;

    /**
     * 查询【请填写功能名称】列表
     */

    @GetMapping("/list")
    public TableDataInfo list(YhBorrow yhBorrow)
    {
        startPage();
        List<YhBorrow> list = yhBorrowService.selectYhBorrowList(yhBorrow);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */

    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('system:borrow:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhBorrow yhBorrow)
    {
        List<YhBorrow> list = yhBorrowService.selectYhBorrowList(yhBorrow);
        ExcelUtil<YhBorrow> util = new ExcelUtil<YhBorrow>(YhBorrow.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhBorrowService.selectYhBorrowById(id));
    }

    /**
     * 新增【请填写功能名称】
     */

    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('system:borrow:add')")
    @PostMapping
    public AjaxResult add(@RequestBody YhBorrow yhBorrow)
    {
        // 获取当前登录用户
        LoginUser loginUser = getLoginUser();
        SysUser sysUser = loginUser.getUser();
        yhBorrow.setBorrowOperator(loginUser.getUser().getNickName());

        System.out.println(loginUser.getUser().getNickName()+"loginUser.getUser().getNickName()");
        return toAjax(yhBorrowService.insertYhBorrow(yhBorrow));
    }

    /**
     * 修改【请填写功能名称】
     */

    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('system:borrow:update')")
    @PutMapping
    public AjaxResult edit(@RequestBody YhBorrow yhBorrow)
    {


        return toAjax(yhBorrowService.updateYhBorrow(yhBorrow));
    }

    /**
     * 删除【请填写功能名称】
     */

    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhBorrowService.deleteYhBorrowByIds(ids));
    }
}
